package com.dx.chat.util;

import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.Image;
import javafx.stage.Stage;

/**
 * Description: 弹框工具类
 *
 * @author rockstarsteve
 * @version 1.0
 * @copyright Copyright (c) 电信
 * @since 2023/9/6
 */
public class AlertUtil {

    private String title;
    private String msg;

    private static Stage stage = new Stage();

    /**
     * 错误消息
     *
     * @param title 标题
     * @param msg   警告消息
     */
    public static void alertError(String title, String msg) {
        Alert alertError = new Alert(AlertType.ERROR);
        alertError.setTitle(title);
        alertError.setHeaderText("");
        alertError.setContentText(msg);
        check(alertError);
        alertError.show();
    }

    /**
     * 提示信息
     *
     * @param title 标题
     * @param msg   提示信息
     */
    public static void alertInfo(String title, String msg) {
        Alert infoAlert = new Alert(AlertType.INFORMATION);
        infoAlert.setTitle(title);
        infoAlert.setHeaderText(null);
        infoAlert.setContentText(msg);
        check(infoAlert);
        infoAlert.show();
    }

    /**
     * 警告消息
     *
     * @param title 标题
     * @param msg   警告消息内容
     * @return
     */
    public static void alertWarn(String title, String msg) {
        Alert warnAlert = new Alert(AlertType.WARNING);
        warnAlert.setTitle(title);
        warnAlert.setHeaderText(null);
        warnAlert.setContentText(msg);
        check(warnAlert);
        warnAlert.show();
    }

    /**
     * 返回确认对话框节点
     *
     * @param title 标题
     * @param msg   对话框信息
     * @return 返回对话框
     */
    public static Alert alertConfirm(String title, String msg) {
        Alert confirmAlert = new Alert(AlertType.CONFIRMATION);
        confirmAlert.setTitle(title);
        confirmAlert.setHeaderText(null);
        confirmAlert.setContentText(msg);
        check(confirmAlert);
        return confirmAlert;
    }

    private static void check(Alert alert) {
        alert.getDialogPane().setStyle("-fx-font-size: 16");
        stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.getIcons().add(new Image(AlertUtil.class.getResourceAsStream("/images/electron.png")));
    }


}
